
// 动画
importClass(android.animation.ObjectAnimator)
importClass(android.animation.AnimatorSet)
importClass(android.animation.Animator)
importClass(android.view.View)
importClass(android.graphics.Color);
importClass(android.graphics.drawable.GradientDrawable);
importClass(android.text.Spannable);
importClass(android.text.SpannableStringBuilder);
importClass(android.text.style.ForegroundColorSpan);
importClass(android.graphics.LinearGradient);
importClass(android.graphics.Shader);
importClass(android.graphics.Bitmap);
importClass(android.graphics.BitmapFactory);
importClass(android.graphics.BitmapShader);

module.exports = function () {
    let animationDelay = 250
    let t = this
    console.log("-------_>")
    
    // console.log(this)

    this.dh = {
        //定义弹出配置动画
        open_pupwindow : function (view, fun) {
            animator1 = ObjectAnimator.ofFloat(view, "translationY", t.store.__const__.HEIGHT, 0);
            set = new AnimatorSet();
            set.playSequentially(animator1);
            set.setDuration(animationDelay);
            set.addListener(new Animator.AnimatorListener({
                onAnimationStart: function(animation) {
                    // view.setVisibility(View.VISIBLE)
                    fun(animation)
                    
                }
            }))
            set.start();
        },

        //定义关闭配置动画
        close_pupwindow: function(view, fun) {
            animator1 = ObjectAnimator.ofFloat(view, "translationY", 0, t.store.__const__.HEIGHT);
            set = new AnimatorSet();
            set.playSequentially(animator1);
            set.setDuration(animationDelay);
            set.addListener(new Animator.AnimatorListener({
                onAnimationStart: function(animation) {
                    // view.setVisibility(View.VISIBLE)
                },
                onAnimationEnd: function(animation) {
                    // view.setVisibility(View.GONE)
                    if (fun != null) {
                        fun(animation)
                    }
                }
            }))
            set.start();
        },

        //定义打开动画
        open_animator: function (view){
            //更加丰富的控制效果
            animator1 = ObjectAnimator.ofFloat(view, "translationX", -1000, 0);
            set = new AnimatorSet();
            set.playSequentially(animator1);
            set.setDuration(animationDelay);
            set.addListener(new Animator.AnimatorListener({
                onAnimationStart: function(animation) {
                    view.setVisibility(View.VISIBLE)
                }
            }))
            set.start();
        },

        //定义点击缩放动画
        click_animator: function (view) {
            animator1 = ObjectAnimator.ofFloat(view, "scaleX", 1, 2, 1);
            animator2 = ObjectAnimator.ofFloat(view, "scaleY", 1, 2, 1);

            set = new AnimatorSet();
            set.playTogether(animator1, animator2);
            set.setDuration(animationDelay);
            set.addListener(new Animator.AnimatorListener({
                onAnimationStart: function(animation) {
                    // view.setVisibility(View.VISIBLE)
                }
            }))
            set.start();
        },

        //定义关闭动画
        close_animator: function(view) {
            //更加丰富的控制效果
            animator1 = ObjectAnimator.ofFloat(view, "translationX", 0, -1000);
            set = new AnimatorSet();
            set.playSequentially(animator1);
            set.setDuration(animationDelay);
            set.addListener(new Animator.AnimatorListener({
                onAnimationEnd: function(animation) {
                    view.setVisibility(View.GONE)
                }
            }))
            set.start();
        },

        //定义靠边动画
        abs_animator: function (view) {
            animator1 = ObjectAnimator.ofFloat(view, "translationX", 0, 80, 0);
            animator2 = ObjectAnimator.ofFloat(view, "translationX", 0, 40, 0);
            animator3 = ObjectAnimator.ofFloat(view, "translationX", 0, 20, 0);
            set = new AnimatorSet();
            set.playSequentially(animator1, animator2, animator3);
            set.setDuration(150);
            set.start();
        },
        // 设置悬浮窗按钮的背景
        setBackgroundRoundRounded : function (view) {
            gradientDrawable = new GradientDrawable();
            gradientDrawable.setShape(GradientDrawable.RECTANGLE);
            gradientDrawable.setColor(Color.parseColor("#4DA9A9A9"));
            gradientDrawable.setCornerRadius(45);
            gradientDrawable.setSize(50, 50);
            gradientDrawable.setStroke(2, Color.parseColor("#ffffff"))
            view.setBackground(gradientDrawable);
        },
        // 设置圆角
        setPopRadio: function (view, color) {
            if (color == null) color = "#ffffff"
            gradientDrawable = new GradientDrawable();
            gradientDrawable.setShape(GradientDrawable.RECTANGLE);
            gradientDrawable.setColor(colors.parseColor(color));
        
            gradientDrawable.setCornerRadii([45, 45, 45, 45, 0,0,0,0,0,0,0,0]);
            gradientDrawable.setSize(50, 50);
            gradientDrawable.setStroke(2, Color.parseColor(color))
            
            view.setBackground(gradientDrawable);
        },
    }
}

